/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Attendents {

    public static boolean insertAttendent(Entity.Attendent att) {
        try {
            String sql = "insert into tblAttendent values(?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, att.get_StudentID());
            ps.setString(2, att.get_SubjectID());
            ps.setInt(3, att.get_DayAttendent());
            ps.setFloat(4, att.get_MoneyAttendent());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Attendents.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateAttendent(Entity.Attendent att){
        try {
            String sql = "update tblAttendent set StudentID=?, SubjectID=?, DayAttentdent=?, MoneyAttendent=?  where AttendentID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, att.get_StudentID());
            ps.setString(2, att.get_SubjectID());
            ps.setInt(3, att.get_DayAttendent());
            ps.setFloat(4, att.get_MoneyAttendent());
            ps.setInt(5, att.get_AttendentID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Attendents.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }        
    }
    
    public static void deleteAttendent(int intAttendentID){
        try {
            String sql = "delete from tblAttendent where AttendentID = " + intAttendentID;
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Attendents.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }


}
